******************************************************************************
*GSW Treasury data
******************************************************************************

local today=c(current_date)

*Import data from Fed website: https://www.federalreserve.gov/data/yield-curve-tables/feds200628.csv
import delimited "https://www.federalreserve.gov/data/yield-curve-tables/feds200628.csv", clear rowrange(9) delimiters(",") varnames(9)

*Save data as an Excel with today's date in name
export excel "../data/gsw_treasurys/raw_data/gsw_bonds_`today'.xlsx", replace firstrow(variables)

*Format date
rename date date_help
gen date=date(date_help, "YMD")
format date %td
order date
drop date_help

*Keep yields and forward rates used in the paper 
keep date sveny01 sveny02 sveny05 sveny10 sveny30 svenf05 svenf09

*Destring
destring *, replace ignore("NA")

*Generate 5y5y forward rate
generate fwd5y5y = sveny10  + (sveny10 - sveny05)

**Variable labels
local treasuries "1 2 5 10 30"
foreach treasury of local treasuries{
	if `treasury' == 10 | `treasury'==30{
		local name sveny`treasury'
	}
	else{
		local name sveny0`treasury'
	}
	label variable `name' "`treasury'y Treasury zero-coupon yield (Fed/GSW)"
}

local forward "5 9"
foreach f of local forward{
	local name svenf0`f'
	label variable `name' "`f'y Instantaneous forward rate (Fed/GSW)"
}

label variable fwd5y5y "5y5y zero coupon rate (calculated with Fed/GSW data)"

*Save
compress
save "../data/gsw_treasurys/clean_data/gsw_treasurys.dta", replace
